package com.example.elmmerchants.SQL;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Types;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Add_Merchant_SQL {

    String email;
    String user_name;
    String password;
    int shop_information;
    int qualification_information;
    int legal_information;
    int is_open;
    String shop_category;
    double shop_star;
    String shop_introduction;
    int shop_sold;
    int approved;
    String first_category;
    String second_category;
    String shop_name;
    String contact;
    String contact_phone_number;
    String shop_type;
    String shop_picture;
    String shop_place;
    String licence_picture;
    String food_business_licence_picture;
    String id_card_front;
    String id_card_under;
    String phone_id;

    public Add_Merchant_SQL(String email, String user_name, String password, int shop_information, int qualification_information, int legal_information, int is_open, String shop_category, double shop_star, String shop_introduction, int shop_sold, int approved, String first_category, String second_category, String shop_name, String contact, String contact_phone_number, String shop_type, String shop_place, String phone_id) {
        this.email = email;
        this.user_name = user_name;
        this.password = password;
        this.shop_information = shop_information;
        this.qualification_information = qualification_information;
        this.legal_information = legal_information;
        this.is_open = is_open;
        this.shop_category = shop_category;
        this.shop_star = shop_star;
        this.shop_introduction = shop_introduction;
        this.shop_sold = shop_sold;
        this.approved = approved;
        this.first_category = first_category;
        this.second_category = second_category;
        this.shop_name = shop_name;
        this.contact = contact;
        this.contact_phone_number = contact_phone_number;
        this.shop_type = shop_type;
        this.shop_place = shop_place;
        this.phone_id = phone_id;
    }

    public void add_merchant() {
        Connection_SQL userSQL = new Connection_SQL();

        ExecutorService executorService = Executors.newSingleThreadExecutor();
        executorService.execute(() -> {
            try {
                Connection connection = userSQL.connection();
                String sql = "INSERT INTO `elm`.`merchant`(email, user_name, password, shop_information, " +
                        "qualification_information, legal_information, is_open, shop_category, shop_star, shop_introduction, " +
                        "shop_sold, approved, first_category, second_category, shop_name, contact, contact_phone_number, " +
                        "shop_type, shop_picture, shop_place, licence_picture, food_business_licence_picture, id_card_front," +
                        "id_card_under, phone_id, open_hour2, close_hour2) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
                PreparedStatement set_data = connection.prepareStatement(sql);
                set_data.setString(1, email);
                set_data.setString(2, user_name);
                set_data.setString(3, password);
                set_data.setInt(4, shop_information);
                set_data.setInt(5, qualification_information);
                set_data.setInt(6, legal_information);
                set_data.setInt(7, is_open);
                set_data.setString(8, shop_category);
                set_data.setDouble(9, shop_star);
                set_data.setString(10, shop_introduction);
                set_data.setInt(11, shop_sold);
                set_data.setInt(12, approved);
                set_data.setString(13, first_category);
                set_data.setString(14, second_category);
                set_data.setString(15, shop_name);
                set_data.setString(16, contact);
                set_data.setString(17, contact_phone_number);
                set_data.setString(18, shop_type);
                set_data.setBlob(19, (Blob) null);
                set_data.setString(20, shop_place);
                set_data.setBlob(21, (Blob) null);
                set_data.setBlob(22, (Blob) null);
                set_data.setBlob(23, (Blob) null);
                set_data.setBlob(24, (Blob) null);
                set_data.setString(25, phone_id);
                set_data.setString(26, "");
                set_data.setString(27, "");
                set_data.executeUpdate();
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
}
